package com.larry.mr.flow;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @ProjectName map-reduce
 * @Author larry
 * @Date 10:43 2022/3/29
 * @Description TODO
 **/
public class FlowBeanReducer extends Reducer<Text,FlowBean,Text,FlowBean> {

    private FlowBean flowBean = new FlowBean();

    @Override
    protected void reduce(Text key, Iterable<FlowBean> values, Context context) throws IOException, InterruptedException {

        long sum_upFlow = 0;
        long sum_downFlow = 0;

        for (FlowBean value : values) {
            sum_upFlow += value.getUpFlow();
            sum_downFlow += value.getDownFlow();
        }

        flowBean.setSum(sum_upFlow,sum_downFlow);

        context.write(key,flowBean);

    }
}
